<?php

namespace App\Admin\Controllers\Api;

use Storage;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class EditorsController extends Controller
{
    public function upload(Request $request)
    {
    	$data = [
    		'success' => false,
		    'msg' => '上传失败!',
	    ];
    	
    	if ($file = $request->file('upload_file')) {
		    $uploadDisk = Storage::disk('alioss');
		    $uploadPath = 'uploads/images/'.date('Ym/d', time());
		    $uploadedFile = $uploadDisk->put($uploadPath, $file);
		    if ($uploadedFile) {
		    	$data['success'] = true;
		    	$data['msg'] = '上传成功';
		    	$data['file_path'] = Storage::url($uploadedFile);
		    }
	    }
    	
	    return $data;
    }
}
